package controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.commons.codec.binary.Base64;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import entity.Imge;
import util.ImgCount;
import util.ImgUtils;
@Controller
@RequestMapping("/img/")
public class ImgController {
	private int num;
	@ResponseBody
	@RequestMapping("load")
	public JSON load(String img){
		if(img==null){
			System.out.println("没有获取图片");
			return null;
		}
		
		if(num==10){num=0;}
		String path="f:/imgs/"+num+".png";
		num+=1;
		if(ImgUtils.getImg(img,path)){
		File file=new File(path);
		JSON json=ImgUtils.check(file);
		 return json;
		}else{
			return null;
		}
	}
	@ResponseBody
	@RequestMapping("save")
	public String saveimg(String img,HttpServletRequest request){
		String prop=request.getServletContext().getRealPath("");
		int n=ImgCount.imgname(prop+"/static/employ/a.txt");
		String path=prop+"/static/employ/"+n+".png";
		ImgUtils.getImg(img,path);
		return "/static/employ/"+n+".png";
	}
}
